// source --> https://www.couponat5sm.com/wp-content/plugins/wp-coupons-and-deals-premium/assets/js/main.js?ver=3.1.13 // all coupons archive nav active /* eslint-disable */ jQuery(document).ready(function ($) { function wpcd_moreLessDescription(mLDElements) { let num_words = Number(wpcd_main_js.word_count); let full_description, more, less; if(!mLDElements) { full_description = $('.wpcd-full-description'); more = $('.wpcd-more-description'); less = $('.wpcd-less-description'); } else { full_description = mLDElements.fullDescription; more = mLDElements.more; less = mLDElements.less; } full_description.each(function () { $this = $(this); var full_content = $this.html(); var check = full_content.split(' ').length > num_words; if (check) { var short_content = full_content.split(' ').slice(0, num_words).join(' '); $this.siblings('.wpcd-short-description').html(short_content + '...'); $this.hide(); $this.siblings('.wpcd-less-description').hide(); } else { $(this).siblings('.wpcd-more-description').hide(); $(this).siblings('.wpcd-more-description'); $(this).siblings('.wpcd-less-description').hide(); $(this).siblings('.wpcd-short-description').hide(); } }); // more and less link more.click(function (e) { e.preventDefault(); $(this).siblings('.wpcd-full-description').show(); $(this).siblings('.wpcd-less-description').show(); $(this).siblings('.wpcd-short-description').hide(); $(this).hide(); }); less.click(function (e) { e.preventDefault(); $(this).siblings('.wpcd-short-description').show(); $(this).siblings('.wpcd-more-description').show(); $(this).siblings('.wpcd-full-description').hide(); $(this).hide(); }); }; wpcd_moreLessDescription(); console.log("here") $.each($('#wpcd_cat_ul > li'), function () { if ($(this).children('a').attr('href') === window.location.href) { $(this).children('a').addClass('active'); } }); // $('#wpcd_cat_ul .wpcd_category').on('click', function (e) { // e.preventDefault(); // if ($(this).attr('data-category') !== 'all') { // $('.wpcd_item').hide(); // $('.' + $(this).attr('data-category')).fadeIn(); // } else { // $('.wpcd_item').fadeIn(); // } // }); const CouponsNavigation = { categoriesPaginationSetTimeout: '', jsDataTax: 'data-category', action: document.querySelector('#wpcd_coupon_pagination_wr') && document.querySelector('#wpcd_coupon_pagination_wr').getAttribute('wpcd-data-action') ? document.querySelector('#wpcd_coupon_pagination_wr').getAttribute('wpcd-data-action') : '', couponTemplate: $('#wpcd_coupon_template'), infinityScrollInArchive: document.querySelector('#wpcd_coupon_template') && document.querySelector('#wpcd_coupon_template').getAttribute('wpcd-data-infinity_scroll_in_archive') ? document.querySelector('#wpcd_coupon_template').getAttribute('wpcd-data-infinity_scroll_in_archive') : '', wpcdCatUl: document.querySelector('#wpcd_cat_ul'), wpcdDropbtn: document.querySelector('#wpcd_cat_ul .wpcd_dropbtn'), searchInputField: $('.wpcd_searchbar_search input'), searchText: '', couponPaginationActiveRequest: false, lastScroll: null, // function for generation event wpcdDocumentEventGenerate: function(eventName, element, details) { if (eventName && element) { if (!details) { details = true; } let event = new CustomEvent(eventName, {detail: details, bubbles: true}); element.dispatchEvent(event); } }, infinityScroll: function(event) { if(CouponsNavigation.couponPaginationActiveRequest) return; if(!CouponsNavigation.lastScroll && typeof CouponsNavigation.lastScroll === 'object') { // let scrollTop = $('.wpcd_archive_section').offset().top; // if($(window).scrollTop() > scrollTop - 150) { // //$('html, body').scrollTop(scrollTop - 150) // window.scroll(0, scrollTop - 150) // } CouponsNavigation.lastScroll = $(this).scrollTop(); return; } let currentScroll = $(this).scrollTop(); if (currentScroll <= CouponsNavigation.lastScroll){ CouponsNavigation.lastScroll = currentScroll; return; } CouponsNavigation.lastScroll = currentScroll; let wpcdCouponPaginationWr = document.querySelector('#wpcd_coupon_pagination_wr'); if(wpcdCouponPaginationWr) { const scrollAmount = document.documentElement.scrollTop || document.body.scrollTop; const pagWpCoordsY = wpcdCouponPaginationWr.getBoundingClientRect().top + window.pageYOffset; const windowHeight = window.innerHeight; if ((scrollAmount + windowHeight) >= pagWpCoordsY) { let hrefEl = wpcdCouponPaginationWr.querySelector('.current').nextElementSibling; if(hrefEl) { //window.removeEventListener('scroll', CouponsNavigation.infinityScroll); const href = hrefEl.getAttribute('href'); const href_arr = CouponsNavigation.wpcd_getUrlVar(href); const wpcd_coupon_taxonomy = href_arr['wpcd_category'] ? href_arr['wpcd_category'] : href_arr['wpcd_vendor']; CouponsNavigation.couponPaginationActiveRequest = true; CouponsNavigation.wpcd_ajaxCouponCategoriesPagination(href_arr['wpcd_page_num'], wpcd_coupon_taxonomy); } } } }, wpcd_ajaxCouponCategoriesPagination: function(wpcd_page_num, wpcd_coupon_taxonomy, sectionScrollTop = true) { let wpcdCouponLoader = document.querySelector('.wpcd_coupon_loader'); if (!this.infinityScrollInArchive || wpcd_page_num == 1) { if(sectionScrollTop) { let scrollTop = $('.wpcd_archive_section').offset().top; $('html, body').animate({scrollTop: scrollTop - 150}, 300); } } else { wpcdCouponLoader.classList.add('wpcd_coupon_loader_infinite_scroll'); } wpcdCouponLoader.classList.remove('wpcd_coupon_hidden_loader'); clearTimeout(this.categoriesPaginationSetTimeout); this.categoriesPaginationSetTimeout = setTimeout(function () { let coupon_template; let coupon_items_count; let coupon_sortby; let coupon_exclude_cat; let wpcd_data_coupon_page_url; let wpcd_data_category_coupons; let wpcd_data_vendor_coupons; let wpcd_data_ven_cat_id; let wpcd_coupon_taxonomy_category; let wpcd_coupon_taxonomy_vendor; if ( CouponsNavigation.jsDataTax == 'data-category' ) { wpcd_coupon_taxonomy_category = wpcd_coupon_taxonomy; } else if ( CouponsNavigation.jsDataTax == 'data-vendor' ) { wpcd_coupon_taxonomy_vendor = wpcd_coupon_taxonomy; } let wpcd_coupon_template = $( '#wpcd_coupon_template' ); if ( wpcd_coupon_template.length > 0 ) { coupon_template = wpcd_coupon_template.attr( 'wpcd-data-coupon_template' ); coupon_items_count = wpcd_coupon_template.attr( 'wpcd-data-coupon_items_count' ); coupon_sortby = wpcd_coupon_template.attr( 'wpcd-data-coupon_sortby' ); coupon_exclude_cat = wpcd_coupon_template.attr( 'wpcd-data-coupon_exclude_cat' ); wpcd_data_coupon_page_url = wpcd_coupon_template.attr( 'wpcd-data-coupon_page_url' ); wpcd_data_category_coupons = wpcd_coupon_template.attr( 'wpcd-data_category_coupons' ); wpcd_data_vendor_coupons = wpcd_coupon_template.attr( 'wpcd-data_vendor_coupons' ); wpcd_data_ven_cat_id = wpcd_coupon_template.attr( 'wpcd-data_ven_cat_id' ); } if (!coupon_template) { coupon_template = undefined; } if (!wpcd_page_num) { wpcd_page_num = undefined; } const search_text = CouponsNavigation.searchText ? CouponsNavigation.searchText : undefined; $.ajax({ type: 'post', dataType: 'json', url: wpcd_object.ajaxurl, data: { action: CouponsNavigation.action, security: wpcd_object.security, wpcd_category: wpcd_coupon_taxonomy_category, wpcd_vendor: wpcd_coupon_taxonomy_vendor, coupon_template: coupon_template, coupon_items_count: coupon_items_count, coupon_sortby: coupon_sortby, coupon_exclude_cat: coupon_exclude_cat, wpcd_data_coupon_page_url: wpcd_data_coupon_page_url, wpcd_data_category_coupons: wpcd_data_category_coupons, wpcd_data_vendor_coupons: wpcd_data_vendor_coupons, wpcd_data_ven_cat_id: wpcd_data_ven_cat_id, wpcd_page_num: wpcd_page_num, search_text: search_text }, success: function (response) { if (response) { const coupon_container = $('.wpcd_coupon_archive_container'); if (coupon_container.length > 0) { let count_down_span; let masterTooltip; let mLDElements; let wpcdCouponUl = coupon_container.find('#wpcd_coupon_ul'); if (!CouponsNavigation.infinityScrollInArchive) { coupon_container.html(response); $('#wpcd_coupon_pagination_wr a.page-numbers').off('click'); $('#wpcd_coupon_pagination_wr a.page-numbers').on('click', function (e) { e.preventDefault(); const href = $(this).attr('href'); const href_arr = CouponsNavigation.wpcd_getUrlVar(href); CouponsNavigation.wpcd_ajaxCouponCategoriesPagination(href_arr['wpcd_page_num'], wpcd_coupon_taxonomy, true); }); masterTooltip = $('.masterTooltip'); } else { $('#wpcd_coupon_pagination_wr').remove(); if(wpcdCouponUl.length) { if(wpcd_page_num == 1) { wpcdCouponUl.html(response); wpcdCouponUl.prepend('
'); } else { wpcdCouponUl.append(''); wpcdCouponUl.append(response); } } else { if(wpcd_page_num == 1) { coupon_container.html(response); wpcdCouponUl.prepend(''); } else { coupon_container.append(''); coupon_container.append(response); } } let boundaryBetweenOldAndNewItems = $('.boundaryBetweenOldAndNewItems'); wpcdCouponLoader.classList.remove('wpcd_coupon_loader_infinite_scroll'); //window.addEventListener('scroll', CouponsNavigation.infinityScroll); let newItems = boundaryBetweenOldAndNewItems.nextAll('.wpcd_item'); if(!newItems.length) { newItems = boundaryBetweenOldAndNewItems.nextAll('.wpcd_coupon_li'); } count_down_span = newItems.find('[data-countdown_coupon]'); masterTooltip = newItems.find('.masterTooltip'); mLDElements = {}; mLDElements.fullDescription = newItems.find('.wpcd-full-description'); mLDElements.more = newItems.find('.wpcd-more-description'); mLDElements.less = newItems.find('.wpcd-less-description'); boundaryBetweenOldAndNewItems.remove(); } wpcdCouponLoader.classList.add('wpcd_coupon_hidden_loader'); wpcd_countDownFun(count_down_span); masterTooltip.hover(function () { var title = $(this).attr('title'); $(this).data('tipText', title).removeAttr('title'); $('') .text(title) .appendTo('body') .fadeIn('slow'); }, function () { $(this).attr('title', $(this).data('tipText')); $('.wpcd-copy-tooltip').remove(); }).mousemove(function (e) { var mousex = e.pageX + 20; var mousey = e.pageY + 10; $('.wpcd-copy-tooltip') .css({top: mousey, left: mousex}) }); if(!wpcd_coupon_taxonomy) wpcd_coupon_taxonomy = 'all'; $.each($('#wpcd_cat_ul li'), function () { if ($(this).children('a').attr(CouponsNavigation.jsDataTax) == wpcd_coupon_taxonomy) { $(this).children('a').addClass('active'); } else { $(this).children('a').removeClass('active'); } }); wpcd_moreLessDescription(mLDElements); } } else { //wpcdCouponLoader.classList.add('wpcd_coupon_hidden_loader'); } }, complete: function (data) { CouponsNavigation.couponPaginationActiveRequest = false; } }); }, 500); }, dropDownContDisplayBlock: function() { $(".wpcd_categories_in_dropdown > div").css('display', 'block'); }, dropDownContDisplayNone: function() { $(".wpcd_categories_in_dropdown > div").css('display', 'none'); }, wpcdCategoriesDropdown: function() { var sw = jQuery(".wpcd_div_nav_block").width(); if (sw < 850) { $(".wpcd_categories_in_dropdown > div").addClass('wpcd_dropdown-content'); $(".wpcd_categories_in_dropdown > a").css('display', 'inline'); //jQuery(".wpcd_categories_full").css('display', 'none'); this.wpcdCatUl.addEventListener('mouseenter', this.dropDownContDisplayBlock, false); this.wpcdCatUl.addEventListener('mouseleave', this.dropDownContDisplayNone, false); this.wpcdDropbtn.addEventListener('click', this.dropDownContDisplayBlock, false); } else { $(".wpcd_categories_in_dropdown > div").removeClass('wpcd_dropdown-content'); $(".wpcd_categories_in_dropdown > a").css('display', 'none'); this.wpcdCatUl.removeEventListener('mouseenter', this.dropDownContDisplayBlock, false); this.wpcdCatUl.removeEventListener('mouseleave', this.dropDownContDisplayNone, false); this.wpcdDropbtn.removeEventListener('click', this.dropDownContDisplayBlock, false); } }, wpcd_getUrlVar: function(urlVar) { if(!urlVar) urlVar = ''; let arrayVar = []; let valueAndKey = []; let resultArray = []; arrayVar = (urlVar.substr(1)).split('&'); if (arrayVar[0] == "") return false; for (let i = 0; i < arrayVar.length; i++) { valueAndKey = arrayVar[i].split('='); resultArray[valueAndKey[0]] = valueAndKey[1]; } return resultArray; }, init: function () { console.log(this.action) console.log(this.infinityScrollInArchive) // getting wpcdJsDataTax value if ($('#wpcd_cat_ul .wpcd_category').attr('data-category')) { this.jsDataTax = 'data-category'; } else if ($('#wpcd_cat_ul .wpcd_category').attr('data-vendor')) { this.jsDataTax = 'data-vendor'; } if(this.infinityScrollInArchive) { window.addEventListener('scroll', this.infinityScroll); } if (this.wpcdCatUl) { $('#wpcd_cat_ul .wpcd_category').on('click', function (e) { e.preventDefault(); CouponsNavigation.wpcdDocumentEventGenerate('mouseleave', CouponsNavigation.wpcdCatUl); const wpcd_coupon_taxonomy = $(this).attr(CouponsNavigation.jsDataTax); CouponsNavigation.searchInputField.val(''); CouponsNavigation.searchText = ''; CouponsNavigation.couponPaginationActiveRequest = true; CouponsNavigation.wpcd_ajaxCouponCategoriesPagination('1', wpcd_coupon_taxonomy, false); }); this.wpcdCategoriesDropdown(); } $('#wpcd_coupon_pagination_wr a.page-numbers').on('click', function (e) { e.preventDefault(); const href = $(this).attr('href'); const href_arr = CouponsNavigation.wpcd_getUrlVar(href); const wpcd_coupon_taxonomy = href_arr['wpcd_category'] ? href_arr['wpcd_category'] : href_arr['wpcd_vendor']; CouponsNavigation.wpcd_ajaxCouponCategoriesPagination(href_arr['wpcd_page_num'], wpcd_coupon_taxonomy, true); }); let delayTimer; this.searchInputField.on('input', function (e) { clearTimeout(delayTimer); delayTimer = setTimeout(() => { CouponsNavigation.searchText = $(this).val(); CouponsNavigation.couponPaginationActiveRequest = true; CouponsNavigation.wpcd_ajaxCouponCategoriesPagination('1', 'all', false); }, 800); }) } } CouponsNavigation.init(); /* $('.wpcd_search2 .wpcd_searchbar_search input').hide(); $('.wpcd_search2 #wpcd_searchbar_search_close').hide(); $('#wpcd_searchbar_search_icon').on('click', function (e) { $('.wpcd_search2 .wpcd_searchbar_search input').fadeIn(); $('.wpcd_search2 #wpcd_searchbar_search_close').fadeIn(); }); $('.wpcd_search2 #wpcd_searchbar_search_close').on('click', function (e) { $('.wpcd_search2 .wpcd_searchbar_search input').fadeOut(); $('.wpcd_search2 #wpcd_searchbar_search_close').fadeOut(); $('.wpcd_item').fadeIn(); $('.wpcd_searchbar_search input').val(''); });*/ // $('#wpcd_searchbar_search_icon').on('click', function (e) { // $('.wpcd_searchbar_search input').fadeIn(); // $('#wpcd_searchbar_search_close').fadeIn(); // }); // $('#wpcd_searchbar_search_close').on('click', function (e) { // $('.wpcd_searchbar_search input').fadeOut(); // $('#wpcd_searchbar_search_close').fadeOut(); // $('.wpcd_item').fadeIn(); // $('.wpcd_searchbar_search input').val(''); // }); function wpcd_countDownFun(count_down_span) { if(!count_down_span) { count_down_span = $('[data-countdown_coupon]'); } count_down_span.each(function () { var $this = $(this), finalDate = $(this).data('countdown_coupon'); $this.countdown(finalDate, function (event) { var format = '%M ' + wpcd_main_js.minutes + ' %S ' + wpcd_main_js.seconds; if (event.offset.hours > 0) { format = '%H ' + wpcd_main_js.hours + ' %M ' + wpcd_main_js.minutes + ' %S ' + wpcd_main_js.seconds; } if (event.offset.totalDays > 0) { format = '%-d ' + wpcd_main_js.day + '%!d ' + format; } if (event.offset.weeks > 0) { format = '%-w ' + wpcd_main_js.week + '%!w ' + format; } if (event.offset.weeks == 0 && event.offset.totalDays == 0 && event.offset.hours == 0 && event.offset.minutes == 0 && event.offset.seconds == 0) { jQuery(this).parent().addClass('wpcd-countdown-expired').html(wpcd_main_js.expired_text); } else { jQuery(this).html(event.strftime(format)); } }).on('finish.countdown', function (event) { jQuery('.wpcd-coupon-two-countdown-text').hide(); jQuery(this).html(wpcd_main_js.expired_text).parent().addClass('disabled'); }); }); } wpcd_countDownFun(); function wpcd_couponCountingFun() { $('.wpcd-coupon-click-link').click(function (e) { var $this = $(this), coupon_id = $this.data('id'); var data = { 'action': 'wpcd_coupon_clicked_action', 'security': wpcd_object.security, 'coupon_id': coupon_id, }; jQuery.post(wpcd_object.ajaxurl, data, function (response) { console.log('response', response) }); }); } wpcd_couponCountingFun(); }); jQuery(document).ready(function ($) { // For social share $('.fb-share,.tw-share,.go-share').click(function (e) { e.preventDefault(); window.open($(this).attr('href'), 'fbShareWindow', 'height=450, width=550, top=' + ($(window).height() / 2 - 275) + ', left=' + ($(window).width() / 2 - 225) + ', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0'); return false; }); /* * Vote System */ $('a[class^=wpcd-vote]').click(function (e) { e.preventDefault(); var $this = $(this), coupon_id = $this.data('id'), meta = "up", el_sibling_percentage = $this.siblings(".wpcd-vote-percent"), el_percentage = $('.wpcd-vote-percent[data-id=' + coupon_id + ']'); if ($this.hasClass("wpcd-vote-down")) { meta = "down"; } var data = { 'action': 'wpcd_vote', 'security': wpcd_object.security, 'meta': meta, 'coupon_id': coupon_id, }; jQuery.post(wpcd_object.ajaxurl, data, function (response) { if (response === "Failed") { wpcd_displayMsg(wpcd_main_js.vote_failed, el_percentage, 2000); } else if (response === "voted") { wpcd_displayMsg(wpcd_main_js.vote_already, el_sibling_percentage, 2000); } else { wpcd_displayMsg(wpcd_main_js.vote_success, el_percentage, 2000); setTimeout(function () { wpcd_displayMsg(response, el_percentage, 0); }, 2000); } }); /* * This function dispaly msg in a specific element for a little time * * @param string 'Msg' is the message that will be displayed in the element * @param object 'el' is the element * @param int 'Time' is the time in milliSecond or 0 if this will be the text for ever */ function wpcd_displayMsg(Msg, el, Time = 0) { if (typeof (el) === "object") { if (Time === 0) { el.html(Msg); } else { var old_text = el.html(); el.html(Msg); setTimeout(function () { el.html(old_text); }, Time); } } } }); }); jQuery(document).ready(function ($) { $(document).ready(function () { $('.masterTooltip').hover(function () { var title = $(this).attr('title'); $(this).data('tipText', title).removeAttr('title'); $('') .text(title) .appendTo('body') .fadeIn('slow'); }, function () { $(this).attr('title', $(this).data('tipText')); $('.wpcd-copy-tooltip').remove(); }).mousemove(function (e) { var mousex = e.pageX + 20; var mousey = e.pageY + 10; $('.wpcd-copy-tooltip') .css({top: mousey, left: mousex}) }); }); /*